using System.ServiceModel;
using System.Threading.Tasks;
using System;

namespace Zombie.Services.Definitions
{
#if !SILVERLIGHT
	[ServiceContract(Namespace = "https://zsr.codeplex.com/services/")]
	public interface IInformationService
	{
		[OperationContract]
		Task<ZombieTypeSummaryCollection> ListZombieTypes();

		[OperationContract]
		Task<ZombieTypeDetails> GetZombieTypeDetails(int zombieTypeKey);

		[OperationContract]
		Task<int> LogIncident(SessionToken session, ZombieSighting sighting);
	}
#else
	[ServiceContract(Namespace = "https://zsr.codeplex.com/services/")]
	public interface IInformationService
	{
		[OperationContractAttribute(AsyncPattern = true)]
		IAsyncResult BeginListZombieTypes(AsyncCallback callback, object asyncState);

		ZombieTypeSummaryCollection EndListZombieTypes(IAsyncResult result);

		[OperationContractAttribute(AsyncPattern = true)]
		IAsyncResult BeginGetZombieTypeDetails(int zombieTypeKey, AsyncCallback callback, object asyncState);

		ZombieTypeDetails EndGetZombieTypeDetails(IAsyncResult result);

		[OperationContractAttribute(AsyncPattern = true)]
		IAsyncResult BeginLogIncident(SessionToken session, ZombieSighting sighting, AsyncCallback callback, object asyncState);

		int EndLogIncident(IAsyncResult result);
	}

public static class InformationService
{
	public static Task<ZombieTypeSummaryCollection> ListZombieTypes(this IInformationService client)
	{
		return Task.Factory.FromAsync<ZombieTypeSummaryCollection>(client.BeginListZombieTypes(null, null), client.EndListZombieTypes);
	}

	public static Task<ZombieTypeDetails> GetZombieTypeDetails(this IInformationService client, int zombieTypeKey)
	{
		return Task.Factory.FromAsync<ZombieTypeDetails>(client.BeginGetZombieTypeDetails(zombieTypeKey, null, null), client.EndGetZombieTypeDetails);
	}

	public static Task<int> LogIncident(this IInformationService client, SessionToken session, ZombieSighting sighting)
	{
		return Task.Factory.FromAsync<int>(client.BeginLogIncident(session, sighting, null, null), client.EndLogIncident);
	}
}
#endif
}
